const crypto = require('crypto');
const config = require('../config');
const aesfn = {
    key: config.aesKey,
    aesEncrypt: function(data) {
        const cipher = crypto.createCipher('aes192', this.key);
        let crypted = cipher.update(data, 'utf8', 'hex');
        crypted += cipher.final('hex');
        return crypted;
    },
    aesDecrypt: function(encrypted) {
        const decipher = crypto.createDecipher('aes192', this.key);
        let decrypted = decipher.update(encrypted, 'hex', 'utf8');
        decrypted += decipher.final('utf8');
        return decrypted;
    }
};

module.exports = aesfn;